package moon.core.classdef;

import moon.core.Name;
import moon.core.entity.SignatureEntity;
import moon.core.expression.Expr;
import moon.traverse.Visitor;

/**
 * Attribute of a class.
 * 
 * @author <a href="mailto:rmartico@ubu.es">Ra&uacute;l Marticorena</a>
 */
@SuppressWarnings("serial")
public abstract class AttDec extends SignatureEntity implements Property{
	

	/**
	 * Initializer.	
	 */
	private Expr initializer;
	
	/**
	 * Constructor.
	 * 
	 * @param name name 
	 * @param type type
	 */
	public AttDec(Name name, Type type) {
		super(name, type);		
	}     
	
	
	
	/**
	 * {@inheritDoc}.
	 * 
	 * Format: uniqueNameOfTheClass#nameOfAttDec
	 */
    @Override
	public Name getUniqueName() {    	
		return this.getClassDef().getUniqueName().concat("#" 
				+ this.getName().toString()
				+ ":" + this.getType().getUniqueName().toString());		
	}
	
	/**
     * Accepts the visit. Method from Pattern Design Visitor.
     * 
     * @param visitor visitor
     */
    @Override
    public void accept(Visitor visitor){
    	// Hook method
    	visitor.visit(this);
    }
    
	/**
	 * Checks if it has initializer.
	 * 
	 * @return true if it has an initializer
	 */
	public boolean hasInitializer(){
		return initializer!=null;
	}
	
	/**
	 * Gets the initializer.
	 * 
	 * @return initializer
     * @see #setInitializer
	 */
	public Expr getInitializer(){
		return initializer;
	}
	
	/**
	 * Sets the initializer.
	 * 
	 * @param initializer initializer
	 * @see #getInitializer
	 */
	public void setInitializer(Expr initializer){
		this.initializer = initializer;
	}	
}
